package com.pro.service.imple;

import com.pro.common.GuavaCommon;
import com.pro.mapper.JsActicleCategroyMapper;
import com.pro.pojo.JsActicleCategroy;
import com.pro.pojo.JsProductCategroy;
import com.pro.service.JsActicleCategroyService;
import com.pro.utils.GuavaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * ClassName:JsActicleCategroyServiceImple
 * Package:com.pro.service.imple
 * Description:
 *
 * @Date:2021/11/28 下午 6:32
 * @Author: WYH
 */
@Service
public class JsActicleCategroyServiceImple implements JsActicleCategroyService {

    @Autowired(required = false)
    private JsActicleCategroyMapper jsActicleCategroyMapper;

    /**
     * @author WYH
     * @date 2021/11/28 下午 6:33
     * @content : 查看微圈分类ztree树
     */
    @Override
    public List<JsActicleCategroy> getAllzTree() {
        try {
            Object obj = GuavaUtil.getTenCacheBuild().get(String.valueOf(GuavaCommon.Microcircle), () -> {
                List<JsActicleCategroy> allzTree = jsActicleCategroyMapper.getAllzTree();
                JsActicleCategroy jsActicleCategroy = new JsActicleCategroy();
                jsActicleCategroy.setActicleCategroyId(0);
                jsActicleCategroy.setArtcleCatefroyParentId(-1);
                jsActicleCategroy.setArtcleCategroyName("选择分类类型");
                allzTree.add(jsActicleCategroy);
                return allzTree;
            });
            if (obj instanceof List){
                List<JsActicleCategroy> list = (List<JsActicleCategroy>)obj;
                return list;
            }
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return jsActicleCategroyMapper.getAllzTree();
    }

    /**
     * @author WYH
     * @date 2021/11/28 下午 7:28
     * @content :   添加微圈树节点
     */
    @Override
    public Boolean addActicleCategroy(JsActicleCategroy jsActicleCategroy) {
        jsActicleCategroy.setCreateDate(new Date());
        Boolean aBoolean = jsActicleCategroyMapper.addActicleCategroy(jsActicleCategroy);
        if (aBoolean){
            GuavaUtil.getTenCacheBuild().invalidate(String.valueOf(GuavaCommon.Microcircle));
        }
        return aBoolean;
    }

    @Override
    public Boolean delActicleCategroy(Integer acticleCategroyId){
        Boolean aBoolean = jsActicleCategroyMapper.delActicleCategroy(acticleCategroyId);
        if (aBoolean){
            GuavaUtil.getTenCacheBuild().invalidate(String.valueOf(GuavaCommon.Microcircle));
        }
        return aBoolean;
    }

    @Override
    public Boolean updateActicleCategroy(JsActicleCategroy jsActicleCategroy) {
        jsActicleCategroy.setUpdateDate(new Date());
        Boolean aBoolean = jsActicleCategroyMapper.updateActicleCategroy(jsActicleCategroy);
        if (aBoolean){
            GuavaUtil.getTenCacheBuild().invalidate(String.valueOf(GuavaCommon.Microcircle));
        }
        return aBoolean;
    }
}
